const setStr = params => {
    let arr = []
    for (k in params) {
        let str = k + '=' + params[k]
        arr.push(str)
    }
    return arr
}
function harryAjax(option) {
    return new Promise((res, rej) => {
        const xhr = new XMLHttpRequest()
        xhr.responseType = 'json'
        const str = setStr(option.data)
        if (option.method.toUpperCase() === 'GET') {
            xhr.open('GET', option.url + '?' + str)
            xhr.send()
        } else if (option.method.toUpperCase() === 'POST') {
            xhr.open('POST', option.url)
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
            xhr.send(str)
        }
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    res(xhr.response)
                } else {
                    rej(xhr.response)
                }
            }
        }
    })
}